#!/bin/bash
# This script installs pft and whatever
###SHELLPACK preamble pft-bench 0.12x

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required pft-${VERSION}
###SHELLPACK init_complete

PFT_CLIENT_SWITCH=-t
if [ "$PFT_USE_PROCESSES" = "yes" ]; then
	PFT_CLIENT_SWITCH=-n
fi

# Adhere to benchmark-enforced limit
if [ $PFT_MAX_CLIENTS -gt 128 ]; then
	PFT_MAX_CLIENTS=128
fi

cd $SHELLPACK_SOURCES/pft-${VERSION}-installed || die Failed to cd to pft directory
###SHELLPACK threads_large_stride_begin $PFT_MIN_CLIENTS $PFT_MAX_CLIENTS
	mmtests_activity client ${NR_THREADS}
	monitor_pre_hook $LOGDIR_RESULTS ${NR_THREADS}
	echo -n > $LOGDIR_RESULTS/pft-${NR_THREADS}.log
	for ITER in `seq 1 $PFT_ITERATIONS`; do
		( ./pft \
			-m			$PFT_MAPPING_SIZE \
			$PFT_CLIENT_SWITCH	${NR_THREADS}		  \
			2>&1 | tee -a $LOGDIR_RESULTS/pft-${NR_THREADS}.log ) \
				|| die Failed to run pft
	done
	monitor_post_hook $LOGDIR_RESULTS ${NR_THREADS}
	CLIENT=$((CLIENT+1))
###SHELLPACK threads_stride_end

exit $SHELLPACK_SUCCESS
